#!/sbin/openrc-run

TAILSCALED_LOGFILE="${TAILSCALED_LOGFILE:-/var/log/${RC_SVCNAME}d.log}"
TAILSCALED_PORT="${TAILSCALED_PORT:-41641}"

supervisor=supervise-daemon

name="tailscaled"
command="/usr/sbin/tailscaled"
command_args="--state=/var/lib/tailscale/tailscaled.state --port ${TAILSCALED_PORT} ${TAILSCALED_OPTS} >>${TAILSCALED_LOGFILE} 2>&1"

output_log=${TAILSCALED_LOGFILE}
error_log=${TAILSCALED_LOGFILE}

pidfile="/run/tailscaled.pid"
respawn_delay=5
respawn_max=0

depend() {
	need net
	after firewall
	use logger
}

start_pre() {
	checkpath -f -m 0644 -o root:root "${TAILSCALED_LOGFILE}"
}
